package api_auth

import (
	"github.com/gin-gonic/gin"
	"wrblog-api-go/app/common/token"
	"wrblog-api-go/app/service/service_sys"
	"wrblog-api-go/pkg/result"
)

// @Tags  System - 认证授权
// @Summary  获取当前用户的登录信息
// @Accept json
// @Produce json
// @Param Authorization header string true "Authorization"
// @Success 200 {object} result.Result "OK"
// @Router /getLoginUser [get]
func ApiLoginUser(c *gin.Context) {
	loginUser := token.GetLoginUser(c)
	result.Ok(loginUser).Json(c)
}

// @Tags  System - 用户管理
// @Summary  获取当前登录用户信息
// @Accept json
// @Produce json
// @Param Authorization header string true "Authorization"
// @Success 200 {object} result.Result "OK"
// @Router /getUserInfo [get]
func ApiUserInfo(c *gin.Context) {
	data := make(map[string]any)
	loginUser := token.GetLoginUser(c)
	sysUser, err := service_sys.GetUserById(loginUser.UserId)
	if err != nil {
		result.Fail(err)
	}
	data["user"] = sysUser
	data["roles"] = loginUser.Roles
	data["permissions"] = loginUser.Permissions
	result.Ok(data).Json(c)
}
